package com.ruoyi.api.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DzErshou;
import com.ruoyi.system.service.IDzErshouService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 二手房Controller
 * 
 * @author ruoyi
 * @date 2023-08-17
 */
@RestController
@RequestMapping("/api/ershou")
public class DzErshouApiController extends BaseController
{
    @Autowired
    private IDzErshouService dzErshouService;

    /**
     * 查询二手房列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DzErshou dzErshou)
    {
        startPage();
        List<DzErshou> list = dzErshouService.selectDzErshouListWeb(dzErshou);
        return getDataTable(list);
    }

    /**
     * 导出二手房列表
     */
    @Log(title = "二手房", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DzErshou dzErshou)
    {
        List<DzErshou> list = dzErshouService.selectDzErshouListWeb(dzErshou);
        ExcelUtil<DzErshou> util = new ExcelUtil<DzErshou>(DzErshou.class);
        util.exportExcel(response, list, "二手房数据");
    }

    /**
     * 获取二手房详细信息
     */
    @GetMapping(value = "/{esId}")
    public AjaxResult getInfo(@PathVariable("esId") Long esId)
    {
        return AjaxResult.success(dzErshouService.selectDzErshouByEsId(esId));
    }

    /**
     * 新增二手房
     */
    @Log(title = "二手房", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DzErshou dzErshou)
    {
        return toAjax(dzErshouService.insertDzErshou(dzErshou));
    }

    /**
     * 修改二手房
     */
    @Log(title = "二手房", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DzErshou dzErshou)
    {
        return toAjax(dzErshouService.updateDzErshou(dzErshou));
    }

    /**
     * 删除二手房
     */
    @Log(title = "二手房", businessType = BusinessType.DELETE)
	@DeleteMapping("/{esIds}")
    public AjaxResult remove(@PathVariable Long[] esIds)
    {
        return toAjax(dzErshouService.deleteDzErshouByEsIds(esIds));
    }
}
